home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / PongDemo.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  5.3 KB  |  138 lines

  1. TextMode(TEXT_OVERLAID)
  2.  
  3. dim x#, y#, bool_X, bool_y, player1_y#, player2_y#, p1_score, p2_score
  4.  
  5. x#=rnd()%3 'randomize the starting point of the ball x position
  6. y#=rnd()%3 'randomize the starting point of the ball y position
  7. bool_x = true 'Test to See if the Ball Needs to go Left or Right
  8. bool_y = true 'Test to See if the Ball Needs to go Up or Down
  9. player1_y# = 0 'Player 1 y position
  10. player2_y# = 0 'Player 2 x position
  11. p1_score = 0 'Player 1 score
  12. p2_score = 0 'Player 2 Score
  13.  
  14. dim bIntro:bIntro=false 'A booleen value to change from the intro to the main game loop
  15.  
  16. goto main 'Go to the Main Game Loop
  17.  
  18. intro:
  19. ResizeText(10,10) ' Make Text Larger(normal is 40,20)
  20. Locate 3,3 ' Center the Text
  21. print"PONG" ' Print Pong
  22. while inkey$() ="2" :bIntro=true:wend ' Pause until user presses 2
  23. DrawText() ' Draw Text in Buffer
  24. cls ' Clear the Screen
  25. return ' return to main
  26.  
  27. scoreboard: 
  28. ResizeText(50,30) ' Make Text Longer
  29. glPushMatrix() ' Push Current OpenGL Matrix
  30. glColor3f(0,0,0.4) ' Color is Medium Blue(RGB)
  31. glTranslatef(-6,3,-6.0) ' Translate to The Top of Screen 
  32. glBegin(GL_QUADS) 
  33. glVertex2f(0, 0.6) ' Top Left
  34. glVertex2f(12, 0.6) ' Top Right
  35. glVertex2f(12, 0) ' Bottom Right
  36. glVertex2f(0, 0) ' Bottom Left
  37. glEnd() ' Done Drawing The ScoreBoard
  38. glPopMatrix() ' Pop Current OpenGL Matrix
  39. printr "Player 1: " ' Print "Player 1"
  40. print p1_score ' Print Player 1 Score
  41. Locate 39,0 ' Move to Far Left of Screen
  42. print "Player 2: " ' Print "Player 2"
  43. Locate 39,1 ' Move to Far Left and Down 1
  44. print p2_score ' Print Player 2 Score
  45. DrawText() ' Draw Text in the Buffer
  46. return ' Return to Main Function
  47.  
  48. main:
  49. while true ' Main Game Loop
  50. glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) ' Clear The Screen And The Depth Buffer
  51. glLoadIdentity() ' Reset The View
  52.  
  53. if bIntro=false then ' if bIntro is False then do Intro
  54. gosub intro ' Go to Intro
  55. ResizeText(60,20) ' Change Text Size
  56. Locate 18,10 ' Center under "Pong"
  57. print"press 2 to start 2 player" ' Print text
  58. DrawText() ' Print Text in Buffer
  59. SwapBuffers() ' Swap Buffers
  60.  
  61. else ' Else end Intro and Begin the Main Game Loop
  62.  
  63. gosub scoreboard ' Go to The ScoreBoard Drawing Function
  64.  
  65. 'BALL-------------------------------------------------------------------------------------------------
  66. glPushMatrix() 
  67. glColor3ub(rnd()%255+10,rnd()%155+10,rnd()%200+20)' Make the Ball Flash using the absolute values(x#,y#)
  68. glTranslatef(0,0.0,-6.0) 
  69. glTranslatef(x#,y#,0) ' Move the Ball with the x# and y# coordinates
  70. glBegin(GL_QUADS) ' Draw Ball as a Cube(Quad)
  71. glVertex2f(-0.05, 0.05) ' Top Left
  72. glVertex2f( 0.05, 0.05) ' Top Right
  73. glVertex2f( 0.05,-0.05) ' Bottom Right
  74. glVertex2f(-0.05,-0.05) ' Bottom Left
  75. glEnd() ' Done Drawing The Ball
  76. glPopMatrix()
  77. glColor3f(1,1,1) ' Reset Color to White
  78.  
  79. 'Player 1(Left Player)-------------------------------------------------------------------------------
  80. glPushMatrix()
  81. glColor3f(1,0.3,0.3) 
  82. glTranslatef(-4,0.0,-6.0) ' Move Left 4 Units
  83. glTranslatef(0,player1_y#,0)
  84. glBegin(GL_QUADS) ' Draw A Quad
  85. glVertex2f(-0.15, 0.5) ' Top Left
  86. glVertex2f( 0.15, 0.5) ' Top Right
  87. glVertex2f( 0.15,-0.5) ' Bottom Right
  88. glVertex2f(-0.15,-0.5) ' Bottom Left
  89. glEnd() ' Done Drawing The Paddle for Player One(right player)
  90. glPopMatrix() 
  91. glColor3f(1,1,1)
  92.  
  93. 'Player 2(Right Player)-------------------------------------------------------------------------------
  94. glPushMatrix()
  95. glColor3f(0.3,0.3,1) 
  96. glTranslatef(4,0.0,-6.0) ' Move Right 4 Units
  97. glTranslatef(0,player2_y#,0)
  98. glBegin(GL_QUADS) ' Draw A Quad
  99. glVertex2f(-0.15, 0.5) ' Top Left
  100. glVertex2f( 0.15, 0.5) ' Top Right
  101. glVertex2f( 0.15,-0.5) ' Bottom Right
  102. glVertex2f(-0.15,-0.5) ' Bottom Left
  103. glEnd() ' Done Drawing The Paddle for Player Two(left player)
  104. glPopMatrix()
  105. glColor3f(1,1,1)
  106.  
  107. 'Player One keyboard control (keeps in bounds)--------------------------------------------------------
  108. if KeyDown("Q")and player1_y#<2.4 then player1_y#=player1_y#+0.05 endif
  109. if KeyDown("A")and player1_y#>-3 then player1_y#=player1_y#-0.05 endif
  110.  
  111. 'Player Two keyboard control (keeps in bounds)--------------------------------------------------------
  112. if ScanKeyDown(VK_UP)and player2_y#<2.4 then player2_y#=player2_y#+0.05 endif
  113. if ScanKeyDown(VK_DOWN)and player2_y#>-3 then player2_y#=player2_y#-0.05 endif
  114.  
  115. 'bounce if player 1 hits(Left Player)-----------------------------------------------------------------
  116. if x#<=-3.75 and x#>=-3.8 and y#<=player1_y#+0.5 and y#>=player1_y#-0.5 then bool_x = true endif
  117.  
  118. 'bounce if player 2 hits(Right Player)----------------------------------------------------------------
  119. if x#>=3.75 and x#<=3.8 and y#<=player2_y#+0.5 and y#>=player2_y#-0.5 then bool_x = false endif 
  120.  
  121. if x#<=-6 then bool_x=true endif ' To Bounce Ball Back if Player Misses(X axis)
  122. if x#>=6 then bool_x=false endif ' Same
  123. if bool_x then x#=x#+0.05 else x#=x#-0.05 endif ' Bool(C++) Value Test Value
  124.  
  125. if y#<=-3 then bool_y=true endif ' Bounce Ball if Player Misses(Y axis)
  126. if y#>=2.9 then bool_y=false endif
  127. if bool_y then y#=y#+0.05 else y#=y#-0.05 endif
  128.  
  129. if x#<=-6 then p1_score=p1_score+1 endif ' If Ball Goes Past the Player then Score Goes
  130. if x#>= 6 then p2_score=p2_score+1 endif ' Up By One Point
  131.  
  132. WaitTimer(10) ' Timer To regulate game speed 
  133. SwapBuffers () 'Swap the OpenGL buffers ' Swap the OpenGL Front and Back Buffers
  134. cls 'Clear Print Screen ' Clear Screen(Needed?)
  135. endif
  136. wend ' End main loop
  137.  
  138.